
from sqlalchemy import create_engine
from mschema.schema_engine import SchemaEngine

db_type = "mysql"
db_host = "47.104.169.43"
db_port = "6603"
db_user_name = "root"
db_pwd = "MYSQL*"
db_schema = "scenic"
db_name = "scenic"

if __name__ == '__main__':
    if db_type=="postgres":
        connstr = "postgresql+psycopg2"
    else:
        connstr = "mysql+pymysql"
    db_engine = create_engine(f"{connstr}://{db_user_name}:{db_pwd}@{db_host}:{db_port}/{db_name}")
    sengine = SchemaEngine(engine=db_engine,schema=db_schema, db_name=db_name)
    scm=sengine.mschema
    mschema_str = scm.to_mschema()

    with open(f'./schemas/{db_name}.txt', 'w', encoding='utf-8') as f:
        f.write(mschema_str)
        f.close()

    scm.save(f'./schemas/{db_name}.json')